﻿#region Disclaimer / License
// Copyright (C) 2011, Kenneth Bergeron, IAP Worldwide Services, Inc
// NOAA :: National Marine Fisheries Service
// 
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
// 
#endregion
using System;
using System.Windows.Forms;

namespace CatchProcessing
{
    /// <summary>
    /// Enter a station number
    /// </summary>
    public partial class NewStationDialog : Form
    {
        // Backing
        private string itsStation;
        /// <summary>
        /// The selected station number
        /// </summary>
        public string Station
        {
            get { return itsStation; }
            set { itsStation = this.StationTextBox.Text = value; }
        }
        /// <summary>
        /// Get a new station number
        /// </summary>
        public NewStationDialog()
        {
            InitializeComponent();
            this.StationTextBox.Width = 3 + System.Windows.Forms.TextRenderer.MeasureText("888", this.StationTextBox.Font).Width;
        }
        /// <summary>
        /// OK pressed
        /// </summary>
        private void OKButton_Click(object sender, EventArgs e)
        {
            int Try;
            if (!int.TryParse(this.StationTextBox.Text, out Try) || Try > 999 || Try < 0)
            {
                MessageBox.Show("Station number must be 3-digit numberic.");
                return;
            }
            itsStation = Try.ToString("000");
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
        /// <summary>
        /// Let user know that there are only 3 digits by beeping
        /// </summary>
        private void StationTextBox_TextChanged(object sender, EventArgs e)
        {
            if(this.StationTextBox.Text.Length > 3)
                System.Media.SystemSounds.Asterisk.Play();
        }
        /// <summary>
        /// Cancel pressed, close
        /// </summary>
        private void CanButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            Close();
        }
    }
}
